
component accessors="true"  output="false" extends="AbsDelegate"
{

	property name="PostFactory" type="it.millemultimedia.easyBlog.factory.PostFactory";

	public it.millemultimedia.easyBlog.delegate.PostDelegate function init( required Any dataObject ){
		
		variables.dataObject = arguments.dataObject;
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.PostValidator function getValidator(){
		
		return getPostFactory().getValidator();
	}
	
	public it.millemultimedia.easyBlog.model.Post function createInstance(){
		
		return getPostFactory().createInstance();
	}

	public void function create( required Any post ){
		
		variables.dataObject.create( argumentCollection=arguments );
		
	}

	public void function update( required Any post ){
		
		variables.dataObject.update( argumentCollection=arguments );
		
	}

	public it.millemultimedia.easyBlog.model.Post function read( required Any post, Boolean lazy="false", boolean adminMode=false ){
	
		var list = "";
		var posts = variables.dataObject.read( arguments.post, arguments.adminMode );
		var idPosts = "";
		var categories = queryNew( 'idcategories' );
		
		if( arguments.lazy eq false ){
		
			if( posts.recordCount ){
			
				idPosts = valueList( posts.idPost );
			
				categories = getCategories( idPosts );
		
			}
			
		}
		
		
		post = getPostFactory().get( posts, categories );
		
		
		return post;
		
	}

	public void function delete( required Any post ){
		
		variables.dataObject.delete( argumentCollection=arguments );
		
	}

	public it.millemultimedia.easyBlog.model.Post[] function list( required Any post, Boolean lazy="true", Numeric start=0, Numeric count=0, boolean adminMode=false  ){
	
		var list = "";
		var posts = variables.dataObject.list( arguments.post, arguments.adminMode );
		var idPosts = "";
		var categories = queryNew( 'idPost' );
		
		if( arguments.lazy eq false ){
			
			if( posts.recordCount ){
				idPosts = valueList( posts.idPost );
				categories = getCategories( idPosts );
			}
		
		}
		
		list = getPostFactory().list( posts, categories, arguments.start, arguments.count );
		
		
		return list;
		
	}

	public Query function getPostCount( required boolean adminMode ){
		
		return variables.dataObject.getPostCount( arguments.adminMode );
		
	}

	private Query function getCategories( required String idPost ){
		
		return variables.dataObject.getCategories( arguments.idPost );
		
	}

}
